/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dawnland03.ui.model.entity;

import java.util.Map;
import java.util.HashMap;
import dawnland03.model.entity.attribute.PhysicalAttribute;
import dawnland03.model.item.ItemType;
import dawnland03.model.entity.EntitySnapshot;

/**
 * @author user
 */

public class UIEntityModel {
    
    public var id:Integer;
    var physicalAttributeSequence : Double []; //a sequence was used (and not a map) due to bound function
    var itemQuantitySequence : Integer [];

    init{
       for(physicalAttribute in PhysicalAttribute.values()){
           insert 0.0 into physicalAttributeSequence;
       }
       for(itemType in ItemType.values()){
           insert 0 into itemQuantitySequence;
       }
    }

    public function update(entitySnapshot : EntitySnapshot){
        updatePhysicalAttributes(entitySnapshot.getPhysicalAttributes());
        updateItems(entitySnapshot.getItems());
    }


    function updatePhysicalAttributes(physicalAttributes : Map){
        for(mapEntry in physicalAttributes.entrySet()){
            var physicalAttribute : PhysicalAttribute = (mapEntry as Map.Entry).getKey() as PhysicalAttribute;
            var value : Double = (mapEntry as Map.Entry).getValue() as Double;
            physicalAttributeSequence[physicalAttribute.getId()] = value;
        }
    }

    bound public function getPhysicalAttribute(physicalAttribute : PhysicalAttribute) : Double {
          return physicalAttributeSequence[physicalAttribute.getId()];
    }

    function updateItems(items : Map){
        for(mapEntry in items.entrySet()){
            var itemType : ItemType = (mapEntry as Map.Entry).getKey() as ItemType;
            var value : Integer = (mapEntry as Map.Entry).getValue() as Integer;
            itemQuantitySequence[itemType.getId()] = value;
        }
    }

    bound public function getItemQuantity(itemType : ItemType) : Integer {
          return itemQuantitySequence[itemType.getId()];
    }
}
